#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include <arpa/inet.h>
#include <memory.h>
#include <iostream>
#include <QProcess>
#include <QFile>
#include <QApplication>
#include <iostream>
#include <fstream>
#include <yaml-cpp/yaml.h>
#include <QDebug>
using namespace std;

int main(int argc,char* argv[]) {
    QApplication a(argc, argv);

    YAML::Node mSave;
    ofstream fout("/home/niudingding/Downloads/save.yaml");
    mSave["network"]["ethernets"]["ens33"]["dhcp4"] = false;
    mSave["network"]["ethernets"]["ens33"]["addresses"][0] = "192.168.133.129/24";
    mSave["network"]["ethernets"]["ens33"]["optional"] = true;
    mSave["network"]["ethernets"]["ens33"]["gateway4"] = "192.168.133.1";
    //mSave["network"]["ethernets"]["ens33"]["nameservers"]["addresses"] = "114.114.114.114";
    mSave["network"]["version"] = 2;
    mSave["network"]["renderer"] = "networkd";
    fout << mSave;
    fout.close();
    system("echo '123' | sudo -S sh -c 'cp /home/niudingding/Downloads/save.yaml /etc/netplan/01-network-manager-all.yaml'");
    system("echo '123' | sudo -S sh -c 'netplan apply'");

    return a.exec();
}
